<!doctype html>
<html class="no-js" lang="en" xmlns:th="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>商城后台</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- favicon
		============================================ -->

    <link rel="shortcut icon" type="image/x-icon" href="img/favicon.ico">

    <!-- Google Fonts
		============================================ -->
    <link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,700,900" rel="stylesheet">

    <!-- Bootstrap CSS
		============================================ -->
    <link rel="stylesheet" href="css/font-awesome.min.css">
    <!-- owl.carousel CSS
		============================================ -->
    <link rel="stylesheet" href="css/owl.carousel.css">
    <link rel="stylesheet" href="css/owl.theme.css">
    <link rel="stylesheet" href="css/owl.transitions.css">
    <!-- animate CSS
		============================================ -->
    <link rel="stylesheet" href="css/animate.css">
    <!-- normalize CSS
		============================================ -->
    <link rel="stylesheet" href="css/normalize.css">
    <!-- meanmenu icon CSS
		============================================ -->
    <link rel="stylesheet" href="css/meanmenu.min.css">
    <!-- main CSS
		============================================ -->
    <link rel="stylesheet" href="css/main.css">
    <!-- educate icon CSS
		============================================ -->
    <link rel="stylesheet" href="css/educate-custon-icon.css">
    <!-- morrisjs CSS
		============================================ -->
    <link rel="stylesheet" href="css/morrisjs/morris.css">
    <!-- mCustomScrollbar CSS
		============================================ -->
    <link rel="stylesheet" href="css/scrollbar/jquery.mCustomScrollbar.min.css">
    <!-- metisMenu CSS
		============================================ -->
    <link rel="stylesheet" href="css/metisMenu/metisMenu.min.css">
    <link rel="stylesheet" href="css/metisMenu/metisMenu-vertical.css">
    <!-- calendar CSS
		============================================ -->
    <link rel="stylesheet" href="css/calendar/fullcalendar.min.css">
    <link rel="stylesheet" href="css/calendar/fullcalendar.print.min.css">
    <!-- style CSS
		============================================ -->
    <link rel="stylesheet" href="css/style.css">
    <!-- responsive CSS
		============================================ -->
    <link rel="stylesheet" href="css/responsive.css">
    <!-- modernizr JS
		============================================ -->
    <script src="js/vendor/modernizr-2.8.3.min.js"></script>


    <!--    bootstrapTbale相关依赖     -------------------------------    -->


    <!-- Bootstrap CSS
		============================================ -->
    <link rel="stylesheet" href="css/bootstrap.min.css">

    <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="css/bootstrap-table.css" rel="stylesheet" type="text/css">
    <!-- Lobibox CSS
   ============================================ -->
    <link rel="stylesheet" href="css/notifications/Lobibox.min.css">

    <!--    jquery js-->
    <script src="js/jquery/jquery-3.3.1.min.js"></script>
    <script src="js/jquery/jquery-migrate-1.0.0.js"></script>


    <!--bootstrap-->

    <script src="js/bootstrap.min.js"></script>
    <script src="js/bootstrap-table.min.js"></script>
    <script src="js/bootstrap-table-zh-CN.js"></script>
    <!-- Lobibox JS
============================================ -->
    <script src="js/notifications/Lobibox.js"></script>


    <!--    时间插件-->

    <link rel="stylesheet" href="css/bootstrap-datetimepicker.css">
    <script src="js/bootstrap-datetimepicker.js"></script>
    <script src="js/bootstrap-datetimepicker.zh-CN.js"></script>


</head>
<!--    获取前台商品的数据-->


<body>
<!--[if lt IE 8]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade
    your browser</a> to improve your experience.</p>
<![endif]-->
<!-- Start Left menu area -->
<div class="left-sidebar-pro">
    <nav id="sidebar" class="">
        <div class="sidebar-header">
            <a href="index.html"><img class="main-logo" src="img/logo/logo.png" alt=""/></a>
            <strong><a href="index.html"><img src="img/logo/logosn.png" alt=""/></a></strong>
        </div>
        <div class="left-custom-menu-adp-wrap comment-scrollbar">
            <nav class="sidebar-nav left-sidebar-menu-pro">
                <ul class="metismenu" id="menu1">
                    <li class="active">
                        <a class="has-arrow" href="index.html">
                            <span class="fa fa-id-card"></span>
                            <span class="mini-click-non">用户信息</span>
                        </a>
                        <ul class="submenu-angle" aria-expanded="true">
                            <li><a title="Dashboard v.1" href="/index.html"><span class="mini-sub-pro">用户列表</span></a>
                            </li>
                            <li style="background-color: #f6f6f6"><a title="Dashboard v.2" href="/goods.html"><span
                                    class="mini-sub-pro">商品列表</span></a>
                            </li>
                            <li><a title="Dashboard v.3" href="/index-2.html"><span class="mini-sub-pro">订单管理</span></a>
                            </li>
                            <li><a title="Dashboard v.4" href="/categoryManagement.html"><span
                                    class="mini-sub-pro">类目管理</span></a></li>
                        </ul>
                    </li>
                    <li>
                        <a title="Landing Page" href="events.html" aria-expanded="false"><span
                                class="fa fa-user-circle-o" aria-hidden="true"></span>
                            <span class="mini-click-non">系统用户</span></a>
                    </li>
                    <li>
                        <a class="has-arrow" href="all-professors.html" aria-expanded="false"><span
                                class="fa fa-cogs"></span> <span class="mini-click-non">系统管理</span></a>
                        <ul class="submenu-angle" aria-expanded="true">
                            <li><a href="all-professors.html"><span class="mini-sub-pro">菜单管理</span></a></li>
                            <li><a href="add-professor.html"><span class="mini-sub-pro">角色管理</span></a></li>
                            <li><a href="edit-professor.html"><span class="mini-sub-pro">字典管理</span></a></li>
                            <li><a href="professor-profile.html"><span class="mini-sub-pro">权限管理</span></a></li>
                        </ul>
                    </li>

                </ul>
            </nav>
        </div>
    </nav>
</div>
<!-- End Left menu area -->
<!-- Start Welcome area -->
<div class="all-content-wrapper">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="logo-pro">
                    <a href="index.html"><img class="main-logo" src="img/logo/logo.png" alt=""/></a>
                </div>
            </div>
        </div>
    </div>
    <div class="header-advance-area">
        <div class="header-top-area">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                        <div class="header-top-wraper">
                            <div class="row">
                                <div class="col-lg-1 col-md-0 col-sm-1 col-xs-12">
                                    <div class="menu-switcher-pro">
                                        <button type="button" id="sidebarCollapse"
                                                class="btn bar-button-pro header-drl-controller-btn btn-info navbar-btn">
                                            <i class="fa fa-bars"></i>
                                        </button>
                                    </div>
                                </div>
                                <div class="col-lg-6 col-md-7 col-sm-6 col-xs-12">
                                    <div class="header-top-menu tabl-d-n">
                                        <ul class="nav navbar-nav mai-top-nav">
                                            <li class="nav-item"><a href="#" class="nav-link">Home</a>
                                            </li>
                                            <li class="nav-item"><a href="#" class="nav-link">About</a>
                                            </li>
                                            <li class="nav-item"><a href="#" class="nav-link">Services</a>
                                            </li>
                                            <li class="nav-item dropdown res-dis-nn">
                                                <a href="#" data-toggle="dropdown" role="button" aria-expanded="false"
                                                   class="nav-link dropdown-toggle">Project <span
                                                        class="angle-down-topmenu"><i
                                                        class="fa fa-angle-down"></i></span></a>
                                                <div role="menu" class="dropdown-menu animated zoomIn">
                                                    <a href="#" class="dropdown-item">Documentation</a>
                                                    <a href="#" class="dropdown-item">Expert Backend</a>
                                                    <a href="#" class="dropdown-item">Expert FrontEnd</a>
                                                    <a href="#" class="dropdown-item">Contact Support</a>
                                                </div>
                                            </li>
                                            <li class="nav-item"><a href="#" class="nav-link">Support</a>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                                <div class="col-lg-5 col-md-5 col-sm-12 col-xs-12">
                                    <div class="header-right-info">
                                        <ul class="nav navbar-nav mai-top-nav header-right-menu">
                                            <li class="nav-item">
                                                <a href="#" data-toggle="dropdown" role="button" aria-expanded="false"
                                                   class="nav-link dropdown-toggle">
                                                    <img src="img/product/pro4.jpg" alt=""/>
                                                    <span class="admin-name" id="loginName"></span>
                                                    <i class="fa fa-angle-down edu-icon edu-down-arrow"></i>
                                                </a>
                                                <ul role="menu"
                                                    class="dropdown-header-top author-log dropdown-menu animated zoomIn">
                                                    <li><a href="#"><span
                                                            class="edu-icon edu-home-admin author-log-ic"></span>My
                                                        Account</a>
                                                    </li>
                                                    <li><a href="#"><span
                                                            class="edu-icon edu-user-rounded author-log-ic"></span>My
                                                        Profile</a>
                                                    </li>
                                                    <li><a href="#"><span
                                                            class="edu-icon edu-money author-log-ic"></span>User Billing</a>
                                                    </li>
                                                    <li><a href="#"><span
                                                            class="edu-icon edu-settings author-log-ic"></span>Settings</a>
                                                    </li>
                                                    <li><a href="#"><span
                                                            class="edu-icon edu-locked author-log-ic"></span>Log Out</a>
                                                    </li>
                                                </ul>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- Mobile Menu start -->
        <div class="mobile-menu-area">
            <div class="container">
                <div class="row">
                    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                        <div class="mobile-menu">
                            <nav id="dropdown">
                                <ul class="mobile-menu-nav">
                                    <li><a data-toggle="collapse" data-target="#Charts" href="#">Home <span
                                            class="admin-project-icon edu-icon edu-down-arrow"></span></a>
                                        <ul class="collapse dropdown-header-top">
                                            <li><a href="index.html">Dashboard v.1</a></li>
                                            <li><a href="index-1.html">Dashboard v.2</a></li>
                                            <li><a href="index-3.html">Dashboard v.3</a></li>
                                            <li><a href="analytics.html">Analytics</a></li>
                                            <li><a href="widgets.html">Widgets</a></li>
                                        </ul>
                                    </li>
                                    <li><a href="events.html">Event</a></li>
                                    <li><a data-toggle="collapse" data-target="#demoevent" href="#">Professors <span
                                            class="admin-project-icon edu-icon edu-down-arrow"></span></a>
                                        <ul id="demoevent" class="collapse dropdown-header-top">
                                            <li><a href="all-professors.html">All Professors</a>
                                            </li>
                                            <li><a href="add-professor.html">Add Professor</a>
                                            </li>
                                            <li><a href="edit-professor.html">Edit Professor</a>
                                            </li>
                                            <li><a href="professor-profile.html">Professor Profile</a>
                                            </li>
                                        </ul>
                                    </li>
                                    <li><a data-toggle="collapse" data-target="#demopro" href="#">Students <span
                                            class="admin-project-icon edu-icon edu-down-arrow"></span></a>
                                        <ul id="demopro" class="collapse dropdown-header-top">
                                            <li><a href="all-students.html">All Students</a>
                                            </li>
                                            <li><a href="add-student.html">Add Student</a>
                                            </li>
                                            <li><a href="edit-student.html">Edit Student</a>
                                            </li>
                                            <li><a href="student-profile.html">Student Profile</a>
                                            </li>
                                        </ul>
                                    </li>
                                    <li><a data-toggle="collapse" data-target="#democrou" href="#">Courses <span
                                            class="admin-project-icon edu-icon edu-down-arrow"></span></a>
                                        <ul id="democrou" class="collapse dropdown-header-top">
                                            <li><a href="all-courses.html">All Courses</a>
                                            </li>
                                            <li><a href="add-course.html">Add Course</a>
                                            </li>
                                            <li><a href="edit-course.html">Edit Course</a>
                                            </li>
                                            <li><a href="course-profile.html">Courses Info</a>
                                            </li>
                                            <li><a href="course-payment.html">Courses Payment</a>
                                            </li>
                                        </ul>
                                    </li>
                                    <li><a data-toggle="collapse" data-target="#demolibra" href="#">Library <span
                                            class="admin-project-icon edu-icon edu-down-arrow"></span></a>
                                        <ul id="demolibra" class="collapse dropdown-header-top">
                                            <li><a href="library-assets.html">Library Assets</a>
                                            </li>
                                            <li><a href="add-library-assets.html">Add Library Asset</a>
                                            </li>
                                            <li><a href="edit-library-assets.html">Edit Library Asset</a>
                                            </li>
                                        </ul>
                                    </li>
                                    <li><a data-toggle="collapse" data-target="#demodepart" href="#">Departments <span
                                            class="admin-project-icon edu-icon edu-down-arrow"></span></a>
                                        <ul id="demodepart" class="collapse dropdown-header-top">
                                            <li><a href="departments.html">Departments List</a>
                                            </li>
                                            <li><a href="add-department.html">Add Departments</a>
                                            </li>
                                            <li><a href="edit-department.html">Edit Departments</a>
                                            </li>
                                        </ul>
                                    </li>
                                    <li><a data-toggle="collapse" data-target="#demo" href="#">Mailbox <span
                                            class="admin-project-icon edu-icon edu-down-arrow"></span></a>
                                        <ul id="demo" class="collapse dropdown-header-top">
                                            <li><a href="mailbox.html">Inbox</a>
                                            </li>
                                            <li><a href="mailbox-view.html">View Mail</a>
                                            </li>
                                            <li><a href="mailbox-compose.html">Compose Mail</a>
                                            </li>
                                        </ul>
                                    </li>
                                    <li><a data-toggle="collapse" data-target="#Miscellaneousmob" href="#">Interface
                                        <span class="admin-project-icon edu-icon edu-down-arrow"></span></a>
                                        <ul id="Miscellaneousmob" class="collapse dropdown-header-top">
                                            <li><a href="google-map.html">Google Map</a>
                                            </li>
                                            <li><a href="data-maps.html">Data Maps</a>
                                            </li>
                                            <li><a href="pdf-viewer.html">Pdf Viewer</a>
                                            </li>
                                            <li><a href="x-editable.html">X-Editable</a>
                                            </li>
                                            <li><a href="code-editor.html">Code Editor</a>
                                            </li>
                                            <li><a href="tree-view.html">Tree View</a>
                                            </li>
                                            <li><a href="preloader.html">Preloader</a>
                                            </li>
                                            <li><a href="images-cropper.html">Images Cropper</a>
                                            </li>
                                        </ul>
                                    </li>
                                    <li><a data-toggle="collapse" data-target="#Chartsmob" href="#">Charts <span
                                            class="admin-project-icon edu-icon edu-down-arrow"></span></a>
                                        <ul id="Chartsmob" class="collapse dropdown-header-top">
                                            <li><a href="bar-charts.html">Bar Charts</a>
                                            </li>
                                            <li><a href="line-charts.html">Line Charts</a>
                                            </li>
                                            <li><a href="area-charts.html">Area Charts</a>
                                            </li>
                                            <li><a href="rounded-chart.html">Rounded Charts</a>
                                            </li>
                                            <li><a href="c3.html">C3 Charts</a>
                                            </li>
                                            <li><a href="sparkline.html">Sparkline Charts</a>
                                            </li>
                                            <li><a href="peity.html">Peity Charts</a>
                                            </li>
                                        </ul>
                                    </li>
                                    <li><a data-toggle="collapse" data-target="#Tablesmob" href="#">Tables <span
                                            class="admin-project-icon edu-icon edu-down-arrow"></span></a>
                                        <ul id="Tablesmob" class="collapse dropdown-header-top">
                                            <li><a href="static-table.html">Static Table</a>
                                            </li>
                                            <li><a href="data-table.html">Data Table</a>
                                            </li>
                                        </ul>
                                    </li>
                                    <li><a data-toggle="collapse" data-target="#formsmob" href="#">Forms <span
                                            class="admin-project-icon edu-icon edu-down-arrow"></span></a>
                                        <ul id="formsmob" class="collapse dropdown-header-top">
                                            <li><a href="basic-form-element.html">Basic Form Elements</a>
                                            </li>
                                            <li><a href="advance-form-element.html">Advanced Form Elements</a>
                                            </li>
                                            <li><a href="password-meter.html">Password Meter</a>
                                            </li>
                                            <li><a href="multi-upload.html">Multi Upload</a>
                                            </li>
                                            <li><a href="tinymc.html">Text Editor</a>
                                            </li>
                                            <li><a href="dual-list-box.html">Dual List Box</a>
                                            </li>
                                        </ul>
                                    </li>
                                    <li><a data-toggle="collapse" data-target="#Appviewsmob" href="#">App views <span
                                            class="admin-project-icon edu-icon edu-down-arrow"></span></a>
                                        <ul id="Appviewsmob" class="collapse dropdown-header-top">
                                            <li><a href="basic-form-element.html">Basic Form Elements</a>
                                            </li>
                                            <li><a href="advance-form-element.html">Advanced Form Elements</a>
                                            </li>
                                            <li><a href="password-meter.html">Password Meter</a>
                                            </li>
                                            <li><a href="multi-upload.html">Multi Upload</a>
                                            </li>
                                            <li><a href="tinymc.html">Text Editor</a>
                                            </li>
                                            <li><a href="dual-list-box.html">Dual List Box</a>
                                            </li>
                                        </ul>
                                    </li>
                                    <li><a data-toggle="collapse" data-target="#Pagemob" href="#">Pages <span
                                            class="admin-project-icon edu-icon edu-down-arrow"></span></a>
                                        <ul id="Pagemob" class="collapse dropdown-header-top">
                                            <li><a href="login.html">Login</a>
                                            </li>
                                            <li><a href="register.html">Register</a>
                                            </li>
                                            <li><a href="lock.html">Lock</a>
                                            </li>
                                            <li><a href="password-recovery.html">Password Recovery</a>
                                            </li>
                                            <li><a href="404.html">404 Page</a></li>
                                            <li><a href="500.html">500 Page</a></li>
                                        </ul>
                                    </li>
                                </ul>
                            </nav>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>


    <div style="background-color: #ffffff; border-radius: 3px; padding: 12px; ">

        <table id="goodsDataTable" class="table table-bordered table-striped"></table>

        <div id="goodsTableToolbar">
            <button class="btn btn-success" onclick="showAddGoodsModal()">添加</button>
            <button class="btn btn-primary">导入</button>
            <button class="btn btn-danger">导出</button>
        </div>

        <div class="modal" id="addGoodsModal" data-backdrop="static">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button onclick="destoryAddGoodsModal()" class="close">
                            <span>&times;</span>
                        </button>
                        <h3 class="modal-title">添加商品</h3>
                    </div>
                    <div class="modal-body">
                        <form>
                            <input type="hidden" id="imageServerPath">
                            <div class="form-group">
                                <label for="title">标题</label>
                                <input class="form-control" autocomplete="off" id="title">
                            </div>
                            <div class="form-group">
                                <label for="goodsId">商品id</label>
                                <input class="form-control" autocomplete="off" id="goodsId">
                            </div>
                            <div class="form-group">
                                <label for="items">种类</label>
                                <select class="form-control" id="items">
                                </select>
                            </div>
                            <div class="form-group">
                                <label>展示图<span style="color: red;">(在选择展示图之前必须选种类)</span></label>
                                <div style="margin-bottom: 6px;">
                                    <img src="http://10.3.140.4/default.png" width="158px" id="preDisplayImage"
                                         height="180px">
                                </div>
                                <div class="file-upload-inner file-upload-inner-right ts-forms">
                                    <div class="input append-small-btn">
                                        <div class="file-button">
                                            <input id="displayImage" autocomplete="off"
                                                   onchange="uploadDispalyImage(this)" type="file" name="goodsImage">
                                        </div>
                                        <input type="text" autocomplete="off" id="append-small-btn"
                                               placeholder="no file selected">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="price">价格</label>
                                <input class="form-control" autocomplete="off" id="price">
                            </div>
                            <div class="form-group">
                                <label for="stock">库存</label>
                                <input class="form-control" autocomplete="off" id="stock">
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button onclick="destoryAddGoodsModal()" class="btn btn-danger">取消</button>
                        <button class="btn btn-success" onclick="addGoods()">确认</button>
                    </div>
                </div>
            </div>
        </div>
        <div style="height: 200px;"></div>
    </div>




    <!--        底部结尾-->
    <div class="footer-copyright-area">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12">
                    <div class="footer-copy-right">
                        <p>Copyright © 2018. All rights reserved. Template by <a
                                href="https://colorlib.com/wp/templates/">Colorlib</a></p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<!-- wow JS
    ============================================ -->
<script src="js/wow.min.js"></script>
<!-- price-slider JS
    ============================================ -->
<script src="js/jquery-price-slider.js"></script>
<!-- meanmenu JS
    ============================================ -->
<script src="js/jquery.meanmenu.js"></script>
<!-- owl.carousel JS
    ============================================ -->
<script src="js/owl.carousel.min.js"></script>
<!-- sticky JS
    ============================================ -->
<script src="js/jquery.sticky.js"></script>
<!-- scrollUp JS
    ============================================ -->
<script src="js/jquery.scrollUp.min.js"></script>
<!-- counterup JS
    ============================================ -->
<script src="js/counterup/jquery.counterup.min.js"></script>
<script src="js/counterup/waypoints.min.js"></script>
<script src="js/counterup/counterup-active.js"></script>
<!-- mCustomScrollbar JS
    ============================================ -->
<script src="js/scrollbar/jquery.mCustomScrollbar.concat.min.js"></script>
<script src="js/scrollbar/mCustomScrollbar-active.js"></script>
<!-- metisMenu JS
    ============================================ -->
<script src="js/metisMenu/metisMenu.min.js"></script>
<script src="js/metisMenu/metisMenu-active.js"></script>
<!-- morrisjs JS
    ============================================ -->
<script src="js/morrisjs/raphael-min.js"></script>
<script src="js/morrisjs/morris.js"></script>
<script src="js/morrisjs/morris-active.js"></script>
<!-- morrisjs JS
    ============================================ -->
<script src="js/sparkline/jquery.sparkline.min.js"></script>
<script src="js/sparkline/jquery.charts-sparkline.js"></script>
<script src="js/sparkline/sparkline-active.js"></script>
<!-- calendar JS
    ============================================ -->
<script src="js/calendar/moment.min.js"></script>
<script src="js/calendar/fullcalendar.min.js"></script>
<script src="js/calendar/fullcalendar-active.js"></script>
<!-- plugins JS
    ============================================ -->
<script src="js/plugins.js"></script>
<!-- main JS
    ============================================ -->
<script src="js/main.js"></script>
<!-- tawk chat JS
    ============================================ -->
<script src="js/tawk-chat.js"></script>


</body>

<script>


    /**
     * {
     *           "total": 23,
     *           "rows": [{type: '', }, {}, {}]
     *       }
     */
    $('#goodsDataTable').bootstrapTable({
        url: '/goods/getGoodsByLimit.do',
        method: 'GET',
        columns: [
            // field是返回rows中每个对象的属性名
            {title: '类型', field: 'item.name', align: 'center'},
            {title: '商品编号', field: 'goods.goodsId', align: 'center'},
            {title: '描述信息', field: 'goods.title', align: 'center', formatter: formatTitle},
            {title: '价格', field: 'goods.price', align: 'center'},
            {title: '状态', field: 'goods.status', align: 'center', formatter: formatStatus},
            {title: '库存', field: 'goods.stockNum', align: 'center'},
            {title: '创建日期', field: 'goods.createTime', align: 'center'},
            {title: '更新日期', field: 'goods.updateTime', align: 'center'},
            {title: '操作', align: 'center', formatter: addProcessBtn}
        ],
        /**
         * 决定了在哪边分页：client server, 两种不同的配置决定了服务器端返回的数据格式。
         *  client分页, 服务器端返回的数据  [{}, {}, {}]
         *  server端分页，服务器端返回的数据：{rows:[{}, {}], total: 23}
         */
        sidePagination: 'server',
        pagination: true, //表示使用分页
        toolbar: '#goodsTableToolbar'  //设置工具条
    })

    /**
     * 当内容长度大于30的时候，多余的不显示
     * @param value
     * @returns {string|*}
     */
    function formatTitle(value) {
        var length = value.length; //获取文本长度
        if (length > 30) {
            return value.substring(0, 31) + '...';
        }
        return value;
    }

    // 格式化商品的状态
    function formatStatus(value) {
        if (value == 1) {
            return '<span class="label label-success">可用</span>'
        }
        return '<span class="label label-warning">不可用</span>'
    }

    // 添加操作按钮
    function addProcessBtn(value, row) {
        var goodsId = row.goods.goodsId;
        return '<button onclick="deleteGoods(' + goodsId + ')" class="btn btn-danger btn-xs">删除</button>'
    }


    // 删除对应的商品，实际就是改状态
    function deleteGoods(goodsId) {
        console.log(goodsId)
        $.ajax({
            url: '/goods/changeGoodsStatus.do',
            data: {goodsId: goodsId},
            dataType: 'json',
            type: 'post',
            success: function (_data) {
                // 表示删除成功，更新表格
                if (_data.code > 0) {
                    $('#goodsDataTable').bootstrapTable('refresh');
                } else { // 删除失败，给用户一个提示
                    showErrorBox('删除失败, 请联系管理员.')
                }
            }
        })
    }

    // 显示错误提示信息
    function showErrorBox(msgText) {
        Lobibox.notify('warning', {
            size: 'mini',
            delay: 2000,
            delayIndicator: false,
            title: false, //不给title
            msg: msgText,
            sound: false, // 不要音频
            position: 'bottom left'
        })
    }

    // 隐藏模态框
    function destoryAddGoodsModal() {
        resetModal();
        $('#addGoodsModal').modal('hide');
    }

    /**
     * 上传展示图：
     *    1.在选择图片旁边的那个输入框中显示文件的名字；
     *    2.上传图片。
     *    3.回显图片。
     */
    function uploadDispalyImage(fileTag) {
        var item = $('#items').val(); //取种类的值，目的是上传的文件放在哪个目录下

        var itemAlias = item.split('#')[1];

        var displayImage = fileTag.files[0];
        // console.log(displayImage.name)  //文件的名字，在很多网站中要去判断文件的格式是否正确，要通过后缀来判断
        // console.log(displayImage.size); // 文件的大小，单位是字节，如果要判断多少 M, size / (1024 * 1024) 结果单位就位M
        var name = displayImage.name;


        $('#append-small-btn').val(name);

        var formData = new FormData();
        formData.append('displayImage', displayImage);
        formData.append('itemAlias', itemAlias);


        $.ajax({
            url: '/goods/uploadDispalyImage.do',
            type: 'post',
            dataType: 'json',
            data: formData,
            /**
             * 内容类型。默认值：application/x-www-form-urlencoded;
             * false表示不设置，将FormData原封不动的直接提价服务器端
             */
            contentType: false,
            /**
             * processData 处理数据， 例如get请求，会将data中的数据，name=张三&password=125,
             * 对于FormData包含文件，此处要为false, 禁止转换
             */
            processData: false,
            success: function (_data) {
                // {"filePath":"mobile/147617383170300EfssbV3XDA8PFrTsSj.jpg","imageUrl":"http://localhost/mobile/147617383170300EfssbV3XDA8PFrTsSj.jpg"}
                $('#preDisplayImage').prop('src', _data.imageUrl);  //回显图片
                console.log("图片上传回显数据", _data.imageUrl, _data.filePath)
                $('#imageServerPath').val(_data.filePath);
            }
        })
    }

    // 关闭模态框的时候，重置所有的信息
    function resetModal() {
        $('#imageServerPath').val('');
        $('#items').empty();
        $('#append-small-btn').val('');
        $('#preDisplayImage').prop('src', 'http://10.3.140.185/default.png');

        $('#title').val('');
        $('#price').val('');
        $('#stock').val('');
        $('#displayImage').val('');
    }

    // 添加商品
    function addGoods() {
        var imageServerPath = $('#imageServerPath').val();  //商品的路径
        var item = $('#items').val(); // 1#books 种类
        var itemId = item.split('#')[0]; //获取种类的id
        var price = $('#price').val();  //价格
        var stock = $('#stock').val();
        var title = $('#title').val();
        var goodsId = $('#goodsId').val();
        console.log("添加商品图片路径" + imageServerPath);
        // 构建请求的参数
        var requestParams = {
            smallPic: imageServerPath,
            itemId: itemId,
            price: price,
            stockNum: stock,
            title: title,
            goodsId: goodsId
            // smallPic:
        };

        /**
         * 第一个是地址
         * 第二个是数据
         * 第三个是回调函数
         * 第四个是服务器返回的数据类型
         */
        $.post('/goods/addGoods', requestParams, function (_data) {
            if (_data.code > 0) {
                destoryAddGoodsModal(); //销毁添加商品模态框
                $('#goodsDataTable').bootstrapTable('refresh');
            } else {
                showErrorBox('添加商品失败，请联系管理员.')
            }
        }, 'json');
    }


    /**
     * 展示添加的模态框
     *   1. 首先将所有种类查出来，渲染在模态框中的种类下拉列表中
     *   2. 显示模态框
     */
    function showAddGoodsModal() {
        var items = $('#items');
        items.empty(); //清空种类的下拉列表
        /**
         * 第一个参数url地址
         * 第二个参数是请求的参数
         * 第三个参数是回调方法。
         */
        $.getJSON('/goods/getGoodsAllType.do', {}, function (_data) {
            for (var i = 0; i < _data.length; i++) {
                var item = _data[i];
                // <option value="3#shoes">鞋子</option>
                items.append('<option value="' + (item.id + '#' + item.alias) + '">' + item.name + '</option>')
            }
        });

        $('#addGoodsModal').modal('show');
    }

    $.ajax({
        url: "/loginData.do",
        dataType:"json",
        success:function (data) {
            console.log(data.uname)

            $('#loginName').text(data.uname)
        }
    })

</script>

</html>